const common = require('./webpack.common')
const { merge } = require('webpack-merge')
const webpack = require('webpack')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
// const CopyWebpackPlugin = require('copy-webpack-plugin')
const TerserWebpackPlugin = require('terser-webpack-plugin')
const OptimizeCssAssetsWebpackPlugin  = require('optimize-css-assets-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = merge(common, {
    mode: 'production',
    optimization: {
        usedExports: true,
        // concatenateModules: true,
        minimizer: [ // 一旦设置了minimizer数组，webpack认为要自定义压缩配置，webpack自定义的压缩插件就不会工作了
            new TerserWebpackPlugin(), // webpack自定义的压缩插件不工作，需要安装TerserWebpackPlugin插件来压缩js文件
            new OptimizeCssAssetsWebpackPlugin()
          ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new MiniCssExtractPlugin({
            filename: 'style.css'
          })
    ]
})